package jmine.tec.rpc.client;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertThat;
import jmine.tec.rpc.client.provider.ClientStubFactory;
import jmine.tec.rpc.common.RPCException;
import jmine.tec.rpc.common.serialization.Serializer;
import jmine.tec.rpc.common.serialization.SerializerBuilder;
import jmine.tec.utils.io.http.Connector;

import org.jmock.Mockery;
import org.jmock.integration.junit4.JMock;
import org.jmock.integration.junit4.JUnit4Mockery;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

/**
 * Teste para ClientStubFactory
 * 
 * @author lundberg
 */
@RunWith(JMock.class)
public class AClientStubFactoryShould {

    private final Mockery context = new JUnit4Mockery();

    private final Connector connector = this.context.mock(Connector.class);

    private final Serializer serializer = SerializerBuilder.aSerializer().build();

    private ClientStubFactory factory;

    /**
     * Init
     */
    @Before
    public void init() {
        this.factory = ClientStubFactoryBuilder.aClientStubFactory().with(this.connector).with(this.serializer).build();
    }

    /**
     * Testa se o resultado é do tipo correto.
     */
    @Test
    public void createProxiesForAnnotatedInterfaces() {
        MockRemoteService stub = this.factory.create(MockRemoteService.class, "mock");
        assertThat(stub, is(notNullValue()));
    }

    /**
     * Testa se o resultado é do tipo correto.
     */
    @Test(expected = RPCException.class)
    public void throwErrorOnNotAnnotatedInterfaces() {
        this.factory.create(NotAnnotatedRemoteService.class, "mock");
    }

    /**
     * Testa se o resultado é do tipo correto.
     */
    @Test(expected = RPCException.class)
    public void throwErrorOnClasses() {
        this.factory.create(ClassService.class, "mock");
    }
}
